package com.xmg.server.goods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xmg.server.goods.mapper.CatalogPropertyMapper;
import com.xmg.server.goods.mapper.CatalogPropertyValueMapper;
import com.xmg.shop.api.domain.CatalogProperty;
import com.xmg.shop.api.domain.CatalogPropertyValue;
import com.xmg.shop.api.service.ICatalogPropertyService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class CatalogPropertyServiceImpl implements ICatalogPropertyService {
    @Autowired
    private CatalogPropertyMapper catalogPropertyMapper;
    @Autowired
    private CatalogPropertyValueMapper catalogPropertyValueMapper;

    @Override
    public List<CatalogProperty> getCatalogProperty(Long catalogId) {
        return catalogPropertyMapper.getCatalogProperty(catalogId);
    }

    @Override
    public CatalogProperty get(Long id) {
        return catalogPropertyMapper.selectByPrimaryKey(id);
    }

    @Override
    public int delete(Long id) {
        catalogPropertyValueMapper.deleteByPropertyId(id);
        return catalogPropertyMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int saveOrUpdate(CatalogProperty catalogProperty) {
        if (catalogProperty.getId() != null) {
            catalogPropertyMapper.updateByPrimaryKey(catalogProperty);
        } else {
            catalogPropertyMapper.insert(catalogProperty);
        }
        return 0;
    }

    @Override
    public List<CatalogPropertyValue> getCatalogPropertyValue(Long catalogPropertyId) {
        return catalogPropertyValueMapper.selectByPropertyId(catalogPropertyId);
    }

}
